package com.faeple.user.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.faeple.post.entity.CommentDto;
import com.faeple.post.entity.PostDto;
import com.faeple.user.dao.UserDao;
import com.faeple.user.entity.UserDto;

@Repository
public class SqlMapUserDao implements UserDao {

	@Autowired
	private SqlSession sqlSession;

	@Override
	public int getCountMember() {
		return sqlSession.selectOne("UserMapper.getCountMember");
	}
	
	@Override
	public int memberRegist(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.memberRegist", map);
	}

	@Override
	public String getMemberNum(String id) {
		return sqlSession.selectOne("UserMapper.getMemberIdx", id);
	}

	@Override
	public HashMap<String, Object> login(HashMap<String, String> map) {
		return sqlSession.selectOne("UserMapper.login", map);
	}

	@Override
	public int setProfileImage(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.setProfileImage", map);
	}

	@Override
	public int insertMemberInfo(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.insertMemberInfo", map);
	}

	@Override
	public void setLast_Access(String idx) {
		sqlSession.update("UserMapper.setLast_Access", idx);
	}

	@Override
	public void addAccess_Count(String idx) {
		sqlSession.update("UserMapper.addAccess_Count", idx);
	}

	@Override
	public void memberLeave(String idx) {
		sqlSession.update("UserMapper.memberLeave", idx);
	}

	@Override
	public String getProfileImage(String idx) {
		return sqlSession.selectOne("UserMapper.getProfileImage", idx);
	}

	@Override
	public int modifyAccounts(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.modifyAccounts", map);
	}

	@Override
	public boolean fb_loginFirstUse(String id) {
		boolean check = false;
		int i = sqlSession.selectOne("UserMapper.fb_loginFirstUse", id);
		if(i==0){
			check = true;
		}
		
		return check;
	}

	@Override
	public int fb_memberRegist(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.fb_memberRegist", map);
	}

	@Override
	public UserDto fb_login(String id) {
		return sqlSession.selectOne("UserMapper.fb_login", id);
	}

	@Override
	public UserDto getMemberDataforId(String id) {
		return sqlSession.selectOne("UserMapper.getMemberDataforId", id);
	}

	@Override
	public int getFollowAccept(String member_idx) {
		return sqlSession.selectOne("UserMapper.getFollowAccept", member_idx);
	}

	@Override
	public int follow(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.follow", map);
	}

	@Override
	public int unFollow(HashMap<String, String> map) {
		return sqlSession.delete("UserMapper.unFollow", map);
	}
	
	@Override
	public int getFollowersCnt(String member_idx) {
		return sqlSession.selectOne("UserMapper.getFollowersCnt", member_idx);
	}

	@Override
	public int getFollowingCnt(String member_idx) {
		return sqlSession.selectOne("UserMapper.getFollowingCnt", member_idx);
	}

	@Override
	public int getPostCnt(String member_idx) {
		return sqlSession.selectOne("UserMapper.getPostCnt", member_idx);
	}

	@Override
	public int getLikeCnt(String member_idx) {
		return sqlSession.selectOne("UserMapper.getLikeCnt", member_idx);
	}

	@Override
	public String alreadyFollow(HashMap<String, String> map) {
		return sqlSession.selectOne("UserMapper.alreadyFollow", map);
	}

	@Override
	public int getViewCnt(String member_idx) {
		return sqlSession.selectOne("UserMapper.getViewCnt", member_idx);
	}

	@Override
	public int profileUpdate(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.profileUpdate", map);
	}

	@Override
	public String getCoverImage(String idx) {
		return sqlSession.selectOne("UserMapper.getCoverImage", idx);
	}

	@Override
	public UserDto refreshMemberSession(String member_idx) {
		return sqlSession.selectOne("UserMapper.refreshMemberSession", member_idx);
	}

	@Override
	public int checkId(String id) {
		return sqlSession.selectOne("UserMapper.checkId", id);
	}

	@Override
	public int kakaoMemberRegist(HashMap<String, String> map) {		
		return sqlSession.insert("UserMapper.kakaoMemberRegist", map);
	}

	@Override
	public UserDto kakaoLogin(HashMap<String, String> map) {
		return sqlSession.selectOne("UserMapper.kakaoLogin", map);
	}

	@Override
	public int kakaoMemberRegistCheck(HashMap<String, String> map) {
		return sqlSession.selectOne("UserMapper.kakaoMemberRegistCheck", map);
	}

	@Override
	public int appMemberRegistComplete(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.appMemberRegistComplete", map);
	}

	@Override
	public int addMemberViewCntColumn(String idx) {
		return sqlSession.insert("UserMapper.addMemberViewCntColumn", idx);
	}

	@Override
	public void addViewCnt(String idx) {
		sqlSession.update("UserMapper.addViewCnt", idx);
	}

	@Override
	public int checkEmail(String email) {
		return sqlSession.selectOne("UserMapper.checkEmail", email);
	}

	@Override
	public UserDto loginSuccessGetData(String idx) {
		return sqlSession.selectOne("UserMapper.loginSuccessGetData", idx);
	}

	@Override
	public List<Long> getFollowingList(String idx) {
		return sqlSession.selectList("UserMapper.getFollowingList", idx);
	}

	@Override
	public List<PostDto> getMyPost(HashMap<String, String> map) {
		return sqlSession.selectList("UserMapper.getMyPost", map);
	}

	@Override
	public List<UserDto> getTagUserList(String idx) {
		return sqlSession.selectList("UserMapper.getTagUserList", idx);
	}

	@Override
	public List<UserDto> getFollowingProfile(HashMap<String, String> map) {
		return sqlSession.selectList("UserMapper.getFollowingProfile", map);
	}

	@Override
	public List<UserDto> getFollowerProfile(HashMap<String, String> map) {
		return sqlSession.selectList("UserMapper.getFollowerProfile", map);
	}

	@Override
	public List<PostDto> getUserLikesPost(HashMap<String, String> map) {
		return sqlSession.selectList("UserMapper.getUserLikesPost", map);
	}

	@Override
	public int setCoverImage(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.setCoverImage", map);
	}

	@Override
	public List<CommentDto> getMyComment(HashMap<String, String> param) {
		return sqlSession.selectList("UserMapper.getMyComment", param);
	}

	@Override
	public int getMyCommentCnt(String idx) {
		return sqlSession.selectOne("UserMapper.getMyCommentCnt",idx);
	}

	@Override
	public int writeMemberLeave(HashMap<String, String> param) {
		return sqlSession.insert("UserMapper.writeMemberLeave",param);
	}

	@Override
	public int setAutoLoginKey(HashMap<String, String> param) {
		return sqlSession.update("UserMapper.setAutoLoginKey", param);
	}

	@Override
	public UserDto cookieLogin(String key) {
		return sqlSession.selectOne("UserMapper.cookieLogin", key);
	}

	@Override
	public int setRecoveryPasswdKey(HashMap<String, String> param) {
		return sqlSession.update("UserMapper.setRecoveryPasswdKey", param);
	}

	@Override
	public int checkRecoveryPasswdKey(String key) {
		return sqlSession.selectOne("UserMapper.checkRecoveryPasswdKey", key);
	}

	@Override
	public int recoveryResetPasswd(HashMap<String, String> param) {
		return sqlSession.update("UserMapper.recoveryResetPasswd", param);
	}

	@Override
	public List<HashMap<String, String>> loadPostCover(String idx) {
		return sqlSession.selectList("UserMapper.loadPostCover", idx);
	}

	@Override
	public HashMap<String, Integer> getNotiIsUse(String idx) {
		return sqlSession.selectOne("UserMapper.getNotiIsUse", idx);
	}

	@Override
	public int deleteProfileImage(String idx) {
		return sqlSession.update("UserMapper.deleteProfileImage", idx);
	}

	@Override
	public int addBusinessAccount(HashMap<String, String> param) {
		return sqlSession.insert("UserMapper.addBusinessAccount", param);
	}

	@Override
	public int changeMembertoBusiness(String idx) {
		return sqlSession.update("UserMapper.changeMembertoBusiness", idx);
	}

	@Override
	public int businessmemberRegist(HashMap<String, String> param) {
		return sqlSession.insert("UserMapper.businessmemberRegist", param);
	}
}
